﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PersonaLibrary.Data;
using PersonaLibrary.Search;

namespace PersonaLibrary.ViewModel.EmployeeViewModel
{
    internal class EmployeeSearchVM : SearchViewModel<Employee>
    {
        protected override List<BaseSearchProperty> CreateProeprties()
        {
            List<BaseSearchProperty> properties = new List<BaseSearchProperty>
                                                      {
														  new StringSearchProperty(Parametr)
                                                              {PropertyName = "Surname", DisplayName = "Фамилия"},
                                                          new StringSearchProperty(Parametr)
                                                              {PropertyName = "Name", DisplayName = "Имя"},
                                                          new StringSearchProperty(Parametr)
                                                              {PropertyName = "Patronymic", DisplayName = "Отчество"},
                                                          new BaseSearchProperty(Parametr)
                                                              {PropertyName = "Sex1.Sex1", DisplayName = "Пол"},
                                                          new CollectionSearchProperty<EmployeeNoteLink>(Parametr)
                                                              {
                                                                  PropertyName = "EmployeeNoteLinks",
                                                                  DisplayName = "Заметки",
                                                                  CollectionItemProperty = "Note.Name",
                                                              },
                                                          new CollectionSearchProperty<ConnectionJobEmplDep>(Parametr)
                                                              {
                                                                  PropertyName = "ConnectionJobEmplDeps",
                                                                  DisplayName = "Должность",
                                                                  CollectionItemProperty = "Job.Name",
                                                              },
                                                          new CollectionSearchProperty<ConnectionJobEmplDep>(Parametr)
                                                              {
                                                                  PropertyName = "ConnectionJobEmplDeps",
                                                                  DisplayName = "Отдел",
                                                                  CollectionItemProperty = "Department.Name",
                                                              },
                                                          new CollectionSearchProperty<ConnectionJobEmplDep>(Parametr)
                                                              {
                                                                  PropertyName = "ConnectionJobEmplDeps",
                                                                  DisplayName = "Категория организации",
                                                                  CollectionItemProperty =
                                                                      "Department.Organization.Category",
                                                              },
                                                          new CollectionSearchProperty<ConnectionJobEmplDep>(Parametr)
                                                              {
                                                                  PropertyName = "ConnectionJobEmplDeps",
                                                                  DisplayName = "Название организации",
                                                                  CollectionItemProperty =
                                                                      "Department.Organization.Name",
                                                              },
                                                          new DateSearchProperty(Parametr)
                                                              {DisplayName = "Дата рождения", PropertyName = "Birthday"},
														new StringSearchProperty(Parametr)
                                                              {PropertyName = "InexactBirthday", DisplayName = "Примерная дата рождения"},
                                                      };

            return properties;
        }

        protected override void OnExpresseionCreated(System.Linq.Expressions.LambdaExpression expression)
        {
        	Delegate compiledDelegate = expression.Compile();
            Func<BaseEntity, bool> filter = delegate(BaseEntity ent)
                                          {
											  return (bool)compiledDelegate.DynamicInvoke(new object[] { ent });
                                          };

            CurrentApplication.Filter = new Filter(GetType().Name, typeof(Employee))
                                            {
                                                DisplayName = "Поиск по сотрудникам", 
                                                FuncFilter = filter, 
                                                SubFilter = new AlphabetFilter(typeof(Employee), true) { DisplayName = "Поиск по сотрудникам"}
                                            };
            base.OnExpresseionCreated(expression);
        }
    }
}
